package practice;

import comparator.Employee;

import java.util.Arrays;

/**
 *
 */
public class Practice_03 {
    public static void main(String[] args){
        Employee[] ems = new Employee[]{
                new Employee(18, 2000, "男"),
                new Employee(19, 2000, "女"),
                new Employee(20, 1000, "男"),
                new Employee(18, 20000, "女")
        };

        //sort(ems);
        Arrays.sort(ems);

        for (int i = 0; i < ems.length; i++) {
            System.out.print(ems[i].sarly + " ");
            System.out.print(ems[i].age + " ");
            System.out.print(ems[i].name + " ");
            System.out.println();
        }


    }

    public static void sort(Employee[] ems){
        for (int i = 0; i < ems.length; i++) {
            for (int j = i+1; j < ems.length; j++) {
                if(ems[i].sarly > ems[j].sarly){
                    Employee tmp = ems[i];
                    ems[i] = ems[j];
                    ems[j] = tmp;
                }else if(ems[i].sarly == ems[j].sarly){
                    if(ems[i].age < ems[j].age){
                        Employee tmp = ems[i];
                        ems[i] = ems[j];
                        ems[j] = tmp;
                    }else if(ems[i].age == ems[j].age){
                        if(ems[i].name.compareTo(ems[j].name) > 0){
                            Employee tmp = ems[i];
                            ems[i] = ems[j];
                            ems[j] = tmp;
                        }
                    }
                }
            }
        }
    }
}


